/**
 * @Author Luming
 * @Date 2024/5/7 21:40
 * @Description:
 */
public class UnsafeThreadDemo {
    
    private static int counter = 0;
    
    public static void main(String[] args) {
        Thread thread1 = new Thread(new IncrementCounter());
        Thread thread2 = new Thread(new IncrementCounter());
        
        thread1.start();
        thread2.start();
        
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        System.out.println("Counter: " + counter);
    }
    
    static class IncrementCounter implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 100000; i++) {
                counter++;
            }
        }
    }
}
